<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>座位</title>
</head>
<body>
    
    <div id="checkboxs"></div>
    <p><input type="button" id="buyticket" value="买票"></p>
</body>

<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>

<script>
    var screenId = sessionStorage.getItem("screenId");
    var siteArray = [];
    var ticketdata = [];
    var sitedata = [];
    function AllTicket(){
        var url = "http://localhost:8090/wanda/tickets";
        pdata = {"screenId":screenId}
        $.get(url,pdata,function(jsondata){
            ticketdata = jsondata;
            console.log(ticketdata);
        })
    }
    AllTicket();
    var url = "http://localhost:8090/wanda/sites";
    pdata = {"screenId":screenId}
    $.get(url,pdata,function(jsondata){
        sitedata = jsondata;
        console.log(sitedata)
        if(jsondata.code == "200"){
            for(i=0;i<jsondata.data.length;i++){
                if(ticketdata.data[i].isWicket == 1){
                    $("#checkboxs").append( "<label><input class='seat' type='checkbox' checked disabled value='" +
                  jsondata.data[i].id +
                  "' />" +
                  "</label>");
                }else{
                    $("#checkboxs").append( "<label><input class='seat' type='checkbox'  value='" +
                  jsondata.data[i].id +
                  "' />" +
                  "</label>");
                  if(jsondata.data[i].isExline==1){
                $("#checkboxs").append("<br/>")
                }
                }
               
            }
        }

    },"json")

    $("#checkboxs").on("click","input[class='seat']",function(){
        siteId = $(this).attr("value");
        if(siteArray.indexOf(siteId) == -1){
            siteArray.push(siteId);
        }else{
            siteArray.splice(siteArray.indexOf(siteId),1);
        }
        console.log(siteArray);
    });

    $("#buyticket").on('click',function(){
        console.log("siteArray:" + siteArray);
        var url = "http://localhost:8090/wanda/buyTicket";
        var array =  siteArray.toLocaleString()
        console.log("arrays:" + array)
        pdata = {"arrays":array,"screenId":screenId}
        $.post(url,pdata,function(jsondata){
            alert(jsondata.message)
        },"json");
    })
</script>
</html>